

/*
* Questao_2.asm
*
* Created: 12/11/2012 16:33:19
* Author: Zatta
*/
.include "m8def.inc"

.org 0x000

.equ REG_BOTAO_O = PORTB
.equ REG_BOTAO_D = DDRB
.equ REG_BOTAO_I = PINB
.equ BOTAO1 = 0x01
.equ BOTAO2 = 0x02
.equ BOTAO1_2 = 0x03
.equ variavel = 0x60

Configuracoes:
	LDI R16, BOTAO1_2
	OUT REG_BOTAO_O, R16
	LDI R16, 0xFF
	OUT DDRD,R16

	LDS R16,variavel
	LDI R16,0x01
	STS variavel,R16

Loop:
	LDI R16,BOTAO1_2
	IN R15,PINB
	AND R15,R16
	LDI R16,BOTAO1
	CP R15,R16
	BREQ Subbt1
	LDI R16,BOTAO1_2
	CP R15,R16
	BREQ Subbothbt
	RCALL atraso
	LDS R16,variavel
	LDI R16, 0x01
	STS variavel,R16
	OUT PORTD, R16
	RJMP Loop

Subbt1:
	RCALL Atraso
	LDS R16,variavel
	LSL R16
	STS variavel,R16
	OUT PORTD,R16
	RJMP Loop

Subbothbt:
	RCALL Atraso
	LDS R16,variavel
	LSR R16
	STS variavel,R16
	OUT PORTD,R16
	RJMP Loop

Atraso:
	DEC R3 //decrementa R3, começa com 0x00
	BRNE Atraso //enquanto R3 > 0 fica decrementando R3
	DEC R2
	BRNE Atraso //enquanto R2 > 0 volta decrementar R3
	RET



